package com.we.risk.phoneBook.adm;

import com.alibaba.fastjson.JSONObject;

import static com.we.risk.phoneBook.common.Utils.*;
import static com.we.risk.phoneBook.common.Variables.*;

public class phoneBookObject {
    private String mobile;
    private String name;
    private String mob_prov;
    private String mob_city;
    private String mob_isp;
    private String phn3 = null;
    private boolean isRegBokPhn = false;
    private boolean isTel = false;
    private boolean is400 = false;
    private boolean is9596 = false;
    private boolean isSpc = false;

    private boolean phoIsSamPrv = false;
    private boolean addIsSamPrv = false;
    private boolean pidIsSamPrv = false;
    private boolean phoIsSamCty = false;
    private boolean addIsSamCty = false;
    private boolean pidIsSamCty = false;
    private boolean phoIsSamOpt = false;

    private boolean phoOptIslt = false;
    private boolean phoOptIsyd = false;
    private boolean phoOptIsdx = false;
    private boolean phoOptIsOther = false;

    private int mobLen;
    private int nameLen;
    private int zhNum;
    private int enNum;
    private int numNum;

    private boolean famTag = false;
    private boolean lonTag = false;
    private boolean good1Tag = false;
    private boolean good2Tag = false;
    private boolean badTag = false;

    public phoneBookObject(JSONObject phoneBook, JSONObject userState) {
        if (phoneBook != null) {
            mobile = phoneBook.getString(MOBILE);
            name = phoneBook.getString(NAME);
            // 离线ETL会将原始报文的null替换为空
            mobile = (mobile == null ? "" : mobile);
            name = (name == null ? "" : name);

            mob_prov = phoneBook.getString(MOBPROV);
            mob_city = phoneBook.getString(MOBCITY);
            mob_isp = phoneBook.getString(MOBISP);
            if ("中国联通".equals(mob_isp)) {
                System.out.println(mobile);
            }

            isRegBokPhn = isRegBokPhn(mobile);
            isTel = isTel(mobile);
            is400 = is400(mobile);
            is9596 = is9596(mobile);
            isSpc = isSpc(mobile);

            if (isRegBokPhn) {
                phn3 = mobile.substring(0, 3);
            }

            cmpProvCityOpt(userState);
            // hive avg(null, 10000) = 10000, null不参与计算
            if (mobile != null) {
                mobLen = mobile.length();
            }

            if (name != null) {
                nameLen = hiveUdfLength(name);
                zhNum = hiveUdfLength(name.replaceAll("[^\\W]", ""));
                //                System.out.println(name + "#"+zhNum);
                enNum = hiveUdfLength(name.replaceAll("[^a-zA-Z]", ""));
                numNum = hiveUdfLength(name.replaceAll("[^0-9]", ""));
            }

            famTag = hasFmyTag(name);
            lonTag = hasLonTag(name);
            good1Tag = hasGood1Tag(name);
            good2Tag = hasGood2Tag(name);
            badTag = hasBadTag(name);
        }
    }

    private void cmpProvCityOpt(JSONObject userState) {
        String user_mob_prov = userState.getString(MOBPROV);
        String user_mob_city = userState.getString(MOBCITY);
        String user_mob_isp = userState.getString(MOBISP);
        String user_ad_prov = userState.getString(ADPROV);
        String user_ad_city = userState.getString(ADCITY);
        String user_pid_prov = userState.getString(PIDPROV);
        String user_pid_city = userState.getString(PIDCITY);

        if (mob_prov != null) {
            phoIsSamPrv = mob_prov.equals(user_mob_prov);
            addIsSamPrv = mob_prov.equals(user_ad_prov);
            pidIsSamPrv = mob_prov.equals(user_pid_prov);
        }

        if (mob_city != null) {
            phoIsSamCty = mob_city.equals(user_mob_city);
            addIsSamCty = mob_city.equals(user_ad_city);
            pidIsSamCty = mob_city.equals(user_pid_city);
        }

        if (mob_isp != null) {
            phoIsSamOpt = mob_isp.equals(user_mob_isp);

            if (mob_isp.equals("中国移动")) {
                phoOptIsyd = true;
            } else if (mob_isp.equals("中国联通")) {
                phoOptIslt = true;
            } else if (mob_isp.equals("中国电信")) {
                phoOptIsdx = true;
            } else {
                phoOptIsOther = true;
            }
        }
    }

    public String getMobile() {
        return mobile;
    }

    public String getName() {
        return name;
    }

    public String getMob_prov() {
        return mob_prov;
    }

    public String getMob_city() {
        return mob_city;
    }

    public String getMob_isp() {
        return mob_isp;
    }

    public String getPhn3() {
        return phn3;
    }

    public boolean getRegBokPhn() {
        return isRegBokPhn;
    }

    public boolean getIsTel() {
        return isTel;
    }

    public boolean getIs400() {
        return is400;
    }

    public boolean getIs9596() {
        return is9596;
    }

    public boolean getIsSpc() {
        return isSpc;
    }

    public boolean isPhoIsSamPrv() {
        return phoIsSamPrv;
    }

    public boolean isAddIsSamPrv() {
        return addIsSamPrv;
    }

    public boolean isPidIsSamPrv() {
        return pidIsSamPrv;
    }

    public boolean isPhoIsSamCty() {
        return phoIsSamCty;
    }

    public boolean isAddIsSamCty() {
        return addIsSamCty;
    }

    public boolean isPidIsSamCty() {
        return pidIsSamCty;
    }

    public boolean isPhoIsSamOpt() {
        return phoIsSamOpt;
    }

    public boolean getPhoOptIslt() {
        return phoOptIslt;
    }

    public boolean getPhoOptIsyd() {
        return phoOptIsyd;
    }

    public boolean getPhoOptIsdx() {
        return phoOptIsdx;
    }

    public boolean getPhoOptIsOther() {
        return phoOptIsOther;
    }

    public int getMobLen() {
        return mobLen;
    }

    public int getNameLen() {
        return nameLen;
    }

    public int getZhNum() {
        return zhNum;
    }

    public int getEnNum() {
        return enNum;
    }

    public int getNumNum() {
        return numNum;
    }

    public boolean isFamTag() {
        return famTag;
    }

    public boolean isLonTag() {
        return lonTag;
    }

    public boolean isGood1Tag() {
        return good1Tag;
    }

    public boolean isGood2Tag() {
        return good2Tag;
    }

    public boolean isBadTag() {
        return badTag;
    }
}
